(function(owner) {
	
	owner.domain = {
		API_URL_MANAGER : 'http://wh.ixiaohema.com:8002'
	};
	
	/**
	 * 获取URL参数
	 * @param {Object} name 参数名
	 */
	owner.getRequestParam = function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
		var r = window.location.search.substr(1).match(reg); //匹配目标参数
		if(r != null) return decodeURI(r[2]);
		return null; //返回参数值
	};
	
	/**
	 * 设置Cookie
	 * @param {Object} name
	 * @param {Object} value
	 */
	owner.setCookie = function(name, value) {
		var Days = 30;
		var exp = new Date();
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
	};
	
	/**
	 * 获取Cookie
	 * @param {Object} name
	 */
	owner.getCookie = function(name) {
		var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
		if(arr = document.cookie.match(reg)) {
			return unescape(arr[2]);
		} else {
			return null;
		}
	};
	
	owner.format = function(str) {
		if(arguments.length == 1) return str;
		
		for(var s=str, i=1; i<arguments.length; i++)
			s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);  
		return s;
	};
	
	owner.setJSONLocalStorage = function(key, obj) {
		window.localStorage.setItem(key, JSON.stringify(obj));
	};
	owner.getJSONLocalStorage = function(key) {
		var data = window.localStorage.getItem(key);
		var dataObj = JSON.parse(data);
		return dataObj ;
	};
	
	owner.setJSONSessionStorage = function(key, obj) {
		window.sessionStorage.setItem(key, JSON.stringify(obj));
	};
	owner.getJSONSessionStorage = function(key) {
		var data = window.sessionStorage.getItem(key);
		var dataObj = JSON.parse(data);
		return dataObj ;
	};
	
	//图片预加载
	owner.loadImage = function(url, callback) {
		var img = new Image();
		img.src = url;
		img.onload = function() { //图片下载完毕时异步调用callback函数。 
			callback.call(img); // 将callback函数this指针切换为img。 
		};
		img.onerror = function() {
			img.src = 'img/logo.png';
			img.setAttribute('style', 'width: auto;')
		}
	};
	
	//日期格式化
	owner.dataFormat = function(value, pattern) {
		//将日期字符串转Date
		var date = new Date(value.replace(/-/g, "\/")) ;
		var o = {
			"M+": date.getMonth() + 1, //月份 
			"d+": date.getDate(), //日 
			"h+": date.getHours(), //小时 
			"m+": date.getMinutes(), //分 
			"s+": date.getSeconds(), //秒 
			"q+": Math.floor((date.getMonth() + 3) / 3), //季度 
			"S": date.getMilliseconds() //毫秒 
		};
		if(/(y+)/.test(pattern)) pattern = pattern.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("(" + k + ")").test(pattern)) pattern = pattern.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return pattern;
	};
	
})(window.app={});

